<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@taglib prefix="s" uri="/struts-tags" %>
<%@taglib uri="/authtaglib" prefix="auth" %>
<!DOCTYPE html>
<html>
<head>
<title>舱室状态</title>
<jsp:include page="/include.jsp"/>
<script type="text/javascript">
function doStayQuery() {
        if ($("#room_state_form").form("validate")) {
            $("#stay-datagrid1").datagrid('options').queryParams = serializeObject($('#room_state_form')); //把查询条件赋值给datagrid内部变量
            $("#stay-datagrid1").datagrid('load'); //重新加载
        }
    }
    
    //重置查询条件
function doStayReset() {
 // alert("==================-----------");
    $('#room_state_form').form('reset');
}
   
    
$(function () {
     //查询按纽绑定事件
    $('#btnQuery').bind('click', doStayQuery);
  //  alert("==================");
    //重置按纽绑定事件
    $('#btnReset').bind('click', doStayReset);
    
    $('#stay-datagrid1').datagrid({
    
    
        url: '${pageContext.request.contextPath}/cnbdw/roomAction!getRoomDatasourceList.action',
        border: false,
        singleSelect:true,
        fitColumns: true,
        fit: true,
        pagination: true,
       
        pageList: [30],
        rownumbers: true,
        sortName: 'id',
        sortOrder: 'desc',
        striped: true,
        columns: [
            [
                {field: 'roomNo', title: '房间编号', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (value == '') {
                        return '--'
                    }
                    return value;
                }},
                {field: 'deckInfo', title: '甲板', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.deckInfo, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'fenceInfo', title: '区域', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.regionInfo, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'roomType', title: '舱室种类', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.roomType == null) {
                        return '--'
                    }
                    return getName(rowData.bedInfos[0].room.roomType, $('#stay-datagrid1').datagrid('getData'));
                }},
                {field: 'beds', title: '可入住人数', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = rowData.bedInfos.length;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size--;
                        }
                    });
                    return size;
                }},
                {field: 'haveToStay', title: '已入住人数', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var size = 0;
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            size++;
                        }
                    });
                    return size;
                }},
                {field: 'stayEmp', title: '入住人员', align: 'left',  formatter: function (value, rowData, rowIndex) {
                    if (rowData.bedInfos == null || rowData.bedInfos.length == 0) {
                        return '--'
                    }
                    var emps = [];
                    $.each(rowData.bedInfos, function (index, item) {
                        if (item.employee) {
                            emps.push(item.employee.name);
                        }
                    });
                    return emps.join(", ");
                }}
            ]
        ]
    });
    
     $('#list_select_type').combobox({
            url:'${pageContext.request.contextPath}/roomTypeAction!getTypeSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
        $('#list_select_reqioninfo').combobox({
            url:'${pageContext.request.contextPath}/regionInfoAction!getRegionInfoSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
        $('#list_select_deckinfo').combobox({
            url:'${pageContext.request.contextPath}/deckInfoAction!getDeckInfoSelectData.action',
            valueField:'id',
            textField:'name',
            editable:false
        });
    });
    function getName(objInfo, data) {
    if(objInfo && objInfo.$ref){
        objInfos = jsonPath(data, objInfo.$ref);
        return objInfos[0].name;
    }
    if(objInfo != null){
        return objInfo.name;
    }
    return "--";
}   
</script>
</head>
<body class="easyui-layout">
 <form id="room_state_form" name="room_state_form" method="post">
 	 <div data-options="region:'north'" style="height:80px;border-bottom:none;border-top:none;">
   
       	<table border="0" cellpadding="0" cellspacing="0" height="100%" width="50%">
            <tr>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="datasource_datsourcename">舱室编号：</label>
                    <input type="text" id="datasource_datsourcename" name="roomNo" class="easyui-validatebox"
                           data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_deckinfo">&emsp;甲板：</label>
                    <input type="text" id="list_select_deckinfo" name="deck"
                   			class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td colspan="2" style="width:25%;text-align:right;" nowrap="nowrap">
                    &nbsp;
                </td>
            </tr>
            <tr>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_deviceType">区&nbsp;&nbsp;域：</label>
                    <input type="text" id="list_select_reqioninfo" name="area"
                   		class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td style="width:1%;text-align:left;" nowrap="nowrap">
                    <label for="list_select_type">&emsp;种类：</label>
                    <input type="text" id="list_select_type" name="type"
                   class="easyui-combobox" data-options="validType:'specialCharFilter'"/>
                </td>
                <td colspan="2" style="width:25%;text-align:left;" nowrap="nowrap">
                    &nbsp;
                </td>
            
                
                <td colspan="2" style="width:10%;text-align:left;" nowrap="nowrap">
                    <input type="button" id="btnQuery" onclick=doStayQuery() value="查 询" class="search_btn"/>
                    <input type="button" id="btnReset" onclick=doStayReset() value="重 置" class="reset_btn"/>
                </td>
            </tr>
        </table>
      </div>
        <div data-options="region:'center'" style="border-top:none">
        <table id="stay-datagrid1"></table>
        </div>
      </form>
    </div>
     

</body>
</html>

